package br.com.projeto.web.vraptor.componentes;

import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ResourceBundle;

import br.com.caelum.vraptor.Convert;
import br.com.caelum.vraptor.Converter;
import br.com.caelum.vraptor.converter.ConversionError;
import br.com.caelum.vraptor.ioc.ApplicationScoped;

@Convert(Date.class)
@ApplicationScoped
public class PierDateConverter implements Converter<Date> {

	private DateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm");

	public Date convert(String value, Class<? extends Date> type,
			ResourceBundle bundle) {

		System.out.println(value);
		try {
			return format.parse(value);
		} catch (ParseException e) {
			throw new ConversionError(MessageFormat.format(bundle
					.getString("is_not_a_valid_date"), value));
		}
	}

}
